/**
 * Created by dio on 2017/2/21 0021.
 */
import React from "react";
import {ScrollView, View} from "react-native";
import chjStyle from "../../../CustomStyle";
import ModuleCommonHeader from "../../module/ModuleCommonHeader";
import Util from "../../Util";
import PluginEngineCheck from "./PluginEngineCheck";
import SingleSelectionTextItem from "../common/SingleSelectionTextItem";
import NextButton from "../common/NextButton";
import {ActionConst, Actions} from "react-native-router-flux";

export default class WarrantyOilCheck extends React.Component {
    // 构造函数，可执行初始化操作
    constructor(props) {
        super(props);
        // 在ES6，在构造函数里初始化state
        this.state = {};
        if (!Util.selectCar.warrantyoilcheck) {
            Util.selectCar.warrantyoilcheck = [
                {value: "正常", name: "发动机机油检查"},
                {value: "正常", name: "变速箱油检查"},
                {value: "正常", name: "刹车油检查"},
                {value: "正常", name: "防冻液检查"},
                {value: "正常", name: "转向助力油检查"},
                {value: "正常", name: "离合器油检查"},
                {value: "正常", name: "蓄电池油检查"},
                {value: "正常", name: "蓄电池电压检查"},
                {value: "绿", name: "蓄电池观察孔检查"},
            ];
        }
    }

    // 组件被加载时
    componentDidMount() {

    }

    // 组件即将被卸载时
    componentWillUnmount() {
    }

    // 组件被渲染时
    render() {
        return (
            <View style={chjStyle.mainContainer}>
                <ModuleCommonHeader title='油液检查(02)' clickedLeft={this.clickedBack.bind(this)} leftText='返回'
                                    clickedRight={this.clickedNew.bind(this)} rightText='保存'/>
                <ScrollView
                    style={chjStyle.mainList}>
                    {
                        Util.selectCar.warrantyoilcheck.map((item, i) => this.renderItem(item, i))
                    }
                </ScrollView>
                <NextButton onClickedListener={() => this.clickedNew()}/>
            </View>
        );
    }

    renderItem(item, i) {
        switch (i) {
            case 8:
                return (<SingleSelectionTextItem object={item} optionArray={[{name: "绿"}, {name: "红"}, {name: "黄"}]}/>);
            default:
                return (<SingleSelectionTextItem object={item}
                                                 optionArray={[{name: "正常"}, {name: "缺少"}, {name: "其他"}, {name: "建议维护"}]}/>);
        }
    }

    clickedBack() {
        Actions.pop();
    }

    clickedNew() {
        Util.saveData('cars', Util.selectCar);
        Actions.PluginEngineCheck(
            {
                type: ActionConst.PUSH_OR_POP,
                name: 'PluginEngineCheck',
                component: PluginEngineCheck,
            }
        );
    }
}